KonsolScript Basics

Imagine a programming language plus a game development library packed into one. That is KonsolScript.

A first KonsolScript program

Here's a traditional example of the “Hello World!” program using KonsolScript.

// HelloWorld - A traditional HelloWorld program in KonsolScript
function main() {
  while(lastpress == nochar) {
    Screen:PrintString("Hello World")
    Screen:Render()
  }
}

The code above is simple “Hello World” program. This program will run without error. It will show a window with message saying, “Hello World”.


KonsolScript's runtime environment is packed with a standard header called “console”. This second “Hello World” sample showcases its use.

// HelloUniverse - A not-so traditional HelloWorld program in KonsolScript using a header
#include "console"
function main() {
  write("Hello World")
  end()
}

Compiling

Make sure you have the latest KonsolScript runtime environment. Get it at KonsolScript's website.

Pick one of the two samples above then do the following (choose your platform):

This should produce a file called “HelloWorld.konsl”. This is your compiled HelloWorld Program. This will also be automatically executed.

Running

A compiled KS file ends with KONSL - On Windows, simply double-click on the file to execute. On GNU/Linux, drag the file to the Quixie.desktop.

Closer Look

Let's try to go through each part of the program, step-by-step.


// HelloWorld - A traditional HelloWorld program in KonsolScript

This is a comment. It is a way of, literally, explaining what you meant when you wrote your codes. You can write a one-line comment to your code using “//”.

You can also make a paragraph-like comment using Multiline comment style. Write it between “/*” and “*/”.


function main() {
}

This is our main function called main. Functions are group of code that aim to solve a certain problem. Functions contain logic, which we call algorithm. But usually, beginners tend to write random codes which makes no sense and no logic at all – try not to be one of them. ^_^

The codes are to be written inside the curly-braces.


while(/* ...  */) {
}

Here we have a looping command, while. This helps us prolong the execution of the program.


lastpress == nochar

Inside the while command, we placed a condition. A condition helps the computer to decide if the codes inside the while loop should be executed. Conditions are also helpful to achieve Artificial Intelligence.

lastpress and nochar, by the way, are built-in variables. lastpress corresponds to the last pressed key in the keyboard. While nochar represents that “no key is being pressed”.

The == corresponds to “equal to”. This is a conditional operator, which tries to equate lastpress and nochar.


Screen:PrintString("Hello World")

The command above prints out a message “Hello World” to the primary buffer (which you can't see, yet). Yes, KonsolScript handles a double buffer for you.


Screen:Render()

Lastly, we used a command that the displays the buffer to the window. Try to remove this line and see if you can see `Hello World' at all.

There you go, a very basic program in KonsolScript!

Last Words

If there are errors when you execute it, you'll want to do some debugging. Have fun with that! ^_^


www.konsolscript.org
© 2005-2011 KonsolScript Labs | All Rights Reversed | Licensed under GNU GPL | Designed by Mj Mendoza IV
http://www.sourceforge.net